/* 
  将tokens中的数组按层次进行嵌套处理
*/
export default function nestTokens(tokens) {
  // 结果数组
  var nestedTokens = []
  // 栈容器
  var sections = []
  // 收集器
  var collector = nestedTokens

  for (let i = 0; i < tokens.length; i++) {
    const token = tokens[i]

    switch (token[0]) {
      case '#':
        collector.push(token)
        sections.push(token)
        collector = token[2] = []
        break
      case '/':
        let section = sections.pop()
        collector = sections.length > 0 ? sections[sections.length - 1][2] : nestedTokens
        break
      default:
        collector.push(token)
    }
  }
  return nestedTokens
}
